home *** CD-ROM | disk | FTP | other *** search
- // GETINFO SCRIPTING
- // Imports russian movies info from KinoExpert
-
- (***************************************************
- * Movie information import script for: *
- * KinoExpert Russian, *
- * http://www.kinoexpert.ru/ *
- * *
- * (c) 2004 Serguei Tarassov *
- * http://www.arbinada.com *
- * *
- * Last update: *
- * - 24.10.2004 *
- * *
- * Known issues: *
- * - none *
- * *
- * For use with Ant Movie Catalog 3.4.0 *
- * www.antp.be/software/moviecatalog *
- * *
- * This program is free software; you can *
- * redistribute it and/or modify it under the *
- * terms of the GNU General Public License as *
- * published by the Free Software Foundation; *
- * either version 2 of the License, or (at your *
- * option) any later version. *
- ***************************************************)
-
- program KinoExpert;
- const
- DEBUG_MODE = false;
- DEBUG_FOUND_FILMS_FILENAME = 'KinoExpert_found_results.htm';
- DEBUG_FILM_FILENAME = 'KinoExpert_film.htm';
- BaseAddress = 'http://www.kinoexpert.ru/';
-
- var
- MovieName: string;
-
- { Some utils functions }
- procedure DebugOutput(Value: string);
- begin
- if DEBUG_MODE then
- Input('Watch', 'Value', Value);
- end;
-
- procedure DebugOutputFile(FileName: string; FileText: string);
- var
- Log: TStringList;
- begin
- if DEBUG_MODE then begin
- Log := TStringList.Create;
- Log.Text := FileText;
- Log.SaveToFile(FileName);
- Log.Free;
- end;
- end;
-
- procedure ClearString(var Value: string);
- begin
- HTMLRemoveTags(Value);
- HTMLDecode(Value);
- Value := StringReplace(Value, #13, '');
- Value := StringReplace(Value, #10, '');
- Value := trim(Value);
- end;
-
- procedure ClearText(var Value: string);
- var
- s: string;
- begin
- if length(Value) < 2 then exit;
- Value := trim(Value);
- s := copy(Value, 2, length(Value));
- s := StringReplace(s, '<br>', #13#10);
- s := StringReplace(s, '<BR>', #13#10);
- s := StringReplace(s, '<p>', #13#10#13#10);
- s := StringReplace(s, '<p>', #13#10#13#10);
- Value := copy(Value, 1, 1) + s;
- HTMLRemoveTags(Value);
- HTMLDecode(Value);
- Value := trim(Value);
- end;
-
- procedure RemoveLastDot(var Value: string);
- begin
- if length(Value) > 1 then
- if copy(Value, length(Value), 1) = '.' then begin
- Value := copy(Value, 1, length(Value) - 1);
- end;
- end;
-
-
-
- { Pages parsing }
-
- const
- FoundLabel = '<br>╧ε Γα°σ∞≤ τα∩≡ε±≤ φαΘΣσφε';
- FoundMovieTitleRef = 'index.asp?comm=4&';
- FoundMovieYearLabel = '<td';
-
- procedure AnalyzeFoundFilmsPage(URL: string);
- var
- Page: TStringList;
- FoundTable: string;
- pos1, pos2: integer;
- begin
- Page := TStringList.Create;
- Page.Text := GetPage(URL);
- DebugOutputFile(DEBUG_FOUND_FILMS_FILENAME, Page.Text);
- pos1 := pos(FoundLabel, Page.Text);
- if pos1 <> 0 then begin
- FoundTable := copy(Page.Text, Pos1, length(Page.Text));
- FoundTable := copy(FoundTable, pos('<table', FoundTable), length(FoundTable));
- FoundTable := copy(FoundTable, 1, pos('</table', FoundTable) + 7);
- //DebugOutput(FoundTable);
- if pos(FoundMovieTitleRef, FoundTable) > 0 then
- AddFoundMoviesTitles(FoundTable);
- end;
- Page.Free;
- end;
-
-
- procedure AddFoundMoviesTitles(Table: string);
- var
- CurName, CurURL, SelectedURL, s: string;
- pos2, len: integer;
- begin
- PickTreeClear;
- PickTreeAdd('Movies', '');
- len := length(Table);
- while pos(FoundMovieTitleRef, Table) > 0 do begin
- Table := copy(Table, pos(FoundMovieTitleRef, Table), len);
- pos2 := pos('"', Table);
- CurURL := copy(Table, 1, pos2 - 1);
- //DebugOutput(CurURL);
- Table := copy(Table, pos('>', Table) + 1, len);
- pos2 := pos('<', Table);
- CurName := copy(Table, 1, pos2 - 1);
- ClearString(CurName);
- Table := copy(Table, pos2 + 1, len);
- Table := copy(Table, pos(FoundMovieYearLabel, Table) + 1, len);
- Table := copy(Table, pos('>', Table) + 1, len);
- pos2 := pos('<', Table);
- s := copy(Table, 1, pos2 - 1);
- ClearString(s);
- CurName := CurName + ' ' + s;
- Table := copy(Table, pos2 + 1, len);
- //DebugOutput(CurName);
- PickTreeAdd(CurName, BaseAddress + CurURL);
- end;
-
- if PickTreeExec(SelectedURL) then
- AnalyzeFilmPage(SelectedURL);
- end;
-
-
- const
- FilmTitleAnchor1 = '∩εΩατα≥ⁿ Γ±σ⌡ αΩ≥σ≡εΓ';
- FilmTitleAnchor2 = '╚±Ωα≥ⁿ ∩ε ⌠ε≥ε';
- FilmCountryAnchor = '<b';
- FilmMainTableAnchor = '─δΦ≥.';
- FilmActorsAnchor = '┬ ≡εδ ⌡';
- FilmDirectorAnchor = '╨σµΦ±±σ≡';
- FilmProducerAnchor = '╧≡εΣ■±σ≡';
- FilmAwardsAnchor = '═απ≡αΣ√ Φ ∩≡Φ∞σ≈αφΦ ';
- FilmContentAnchor = '╩≡α≥Ωεσ ±εΣσ≡µαφΦσ';
- FilmImageRefAnchor = '"javascript:window.open(''fotorate.asp?img=';
-
- procedure AnalyzeFilmPage(SelectedURL: string);
- var
- Page: TStringList;
- Content, Value, ImageURL: string;
- pos1, pos2, len: integer;
- begin
- Page := TStringList.Create;
- Page.Text := GetPage(SelectedURL);
- DebugOutputFile(DEBUG_FILM_FILENAME, Page.Text);
-
- SetField(fieldURL, SelectedURL)
-
- len := length(Page.Text);
-
- // Film title
- pos1 := pos(FilmTitleAnchor1, Page.Text);
- if pos1 = 0 then
- pos1 := pos(FilmTitleAnchor2, Page.Text);
- Content := copy(Page.Text, pos1, len);
- Content := copy(Content, pos('>', Content) + 1, len);
- pos2 := pos('</font', Content);
- Value := copy(Content, 1, pos2 - 1);
- ClearString(Value);
- SetField(fieldOriginalTitle, Value)
- SetField(fieldTranslatedTitle, Value)
- //DebugOutput(Value);
- Content := copy(Content, pos2, len);
-
- // Country
- pos2 := pos(FilmCountryAnchor, Content);
- if pos2 > 0 then begin
- Content := copy(Content, pos2, len);
- pos2 := pos('</', Content);
- Value := copy(Content, 1, pos2 - 1);
- ClearString(Value);
- SetField(fieldCountry, Value)
- Content := copy(Content, pos2, len);
- end;
-
- //
- // Film main attributes (small table on top)
- //
- Content := copy(Content, pos(FilmMainTableAnchor, Content), len);
- Content := copy(Content, pos('<td', Content), len);
- Content := copy(Content, pos('>', Content) + 1, len);
- //DebugOutput(Content);
- // Studio
- pos2 := pos('<td', Content);
- Value := copy(Content, 1, pos2 - 1);
- ClearString(Value);
- SetField(fieldSource, Value);
- Content := copy(Content, pos2, len);
- Content := copy(Content, pos('>', Content) + 1, len);
- // Year
- pos2 := pos('<td', Content);
- Value := copy(Content, 1, pos2 - 1);
- ClearString(Value);
- SetField(fieldYear, Value);
- Content := copy(Content, pos2, len);
- Content := copy(Content, pos('>', Content) + 1, len);
- // Category
- pos2 := pos('<td', Content);
- Value := copy(Content, 1, pos2 - 1);
- ClearString(Value);
- SetField(fieldCategory, Value);
- Content := copy(Content, pos2, len);
- Content := copy(Content, pos('>', Content) + 1, len);
- // Length
- pos2 := pos('</td', Content);
- Value := copy(Content, 1, pos2 - 1);
- ClearString(Value);
- SetField(fieldLength, Value);
- Content := copy(Content, pos2, len);
- Content := copy(Content, pos('>', Content) + 1, len);
-
-
- //
- // Other attributes
- //
- // Actors
- pos2 := pos(FilmActorsAnchor, Content);
- if pos2 > 0 then begin
- Content := copy(Content, pos2, len);
- Content := copy(Content, pos('>', Content) + 1, len);
- //DebugOutput(Content);
- pos2 := pos(FilmDirectorAnchor, Content);
- Value := copy(Content, 1, pos2 - 1);
- ClearText(Value);
- SetField(fieldActors, Value);
- Content := copy(Content, pos2, len);
- end;
-
- // Director
- pos2 := pos(FilmDirectorAnchor, Content);
- if pos2 > 0 then begin
- Content := copy(Content, pos2, len);
- Content := copy(Content, pos('>', Content) + 1, len);
- pos2 := pos('<br>', Content);
- Value := copy(Content, 1, pos2 - 1);
- ClearString(Value);
- RemoveLastDot(Value);
- SetField(fieldDirector, Value);
- Content := copy(Content, pos2, len);
- end;
-
- // Producer
- pos2 := pos(FilmProducerAnchor, Content);
- if pos2 > 0 then begin
- Content := copy(Content, pos2, len);
- Content := copy(Content, pos('>', Content) + 1, len);
- pos2 := pos('<br>', Content);
- Value := copy(Content, 1, pos2 - 1);
- ClearString(Value);
- RemoveLastDot(Value);
- SetField(fieldProducer, Value);
- Content := copy(Content, pos2, len);
- end;
-
- // Awards
- pos2 := pos(FilmAwardsAnchor, Content);
- if pos2 > 0 then begin
- Content := copy(Content, pos2, len);
- Content := copy(Content, pos('>', Content) + 1, len);
- pos2 := pos('</div', Content);
- Value := copy(Content, 1, pos2 - 1);
- ClearText(Value);
- SetField(fieldComments, Value);
- Content := copy(Content, pos2, len);
- end;
-
- // Content
- pos2 := pos(FilmContentAnchor, Content);
- if pos2 > 0 then begin
- Content := copy(Content, pos2, len);
- Content := copy(Content, pos('>', Content) + 1, len);
- pos2 := pos('</div', Content);
- Value := copy(Content, 1, pos2 - 1);
- ClearText(Value);
- SetField(fieldDescription, Value);
- Content := copy(Content, pos2, len);
- end;
-
- // image
- pos2 := pos(FilmImageRefAnchor, Content);
- if pos2 > 0 then begin
- Content := copy(Content, pos2, len);
- ImageURL := copy(Content, pos('''', Content) + 1, len);
- pos2 := pos('''', ImageURL);
- Content := copy(Content, pos2, len);
- ImageURL := copy(ImageURL, 1, pos2 - 1);
- ImageURL := BaseAddress + StringReplace(ImageURL, 'fotorate.asp?img=', 'foto/');
- if Input('═αΘΣσφα Ωα≡≥ΦφΩα Ω ⌠Φδⁿ∞≤', '╟απ≡≤τΦ≥ⁿ Ωα≡≥ΦφΩ≤ ?'#13#10'URL:', ImageURL) then
- GetPicture(ImageURL, False); // False = do not store picture externally
- end;
-
-
- Page.Free;
-
- DisplayResults;
- end;
-
- begin
- if CheckVersion(3,4,0) then
- begin
- MovieName := GetField(fieldOriginalTitle);
- if MovieName = '' then
- MovieName := GetField(fieldTranslatedTitle);
- if Input('Import from KinoExpert',
- 'Enter the title of the movie:', MovieName) then
- begin
- AnalyzeFoundFilmsPage(BaseAddress + 'index.asp?comm=1&kw=' +
- UrlEncode(MovieName) + '&fop=false&pack=0#1');
- // AnalyzePage('http://localhost/search1.htm');
- end;
- end else
- ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
- end.
-
-